<template>
  <div>
    <el-table :data="eqlist" stripe @selection-change="handleSelectionChange" style="width: 100%">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="index" width="50"></el-table-column>
      <!-- <el-table-column prop="hash.sup_ep_ename" label="主设备名称"></el-table-column>
      <el-table-column prop="hash.sup_managenum" label="主设备管理编号"></el-table-column> -->
      <el-table-column label="仪器设备名称" width="250">
        <template slot-scope="scope">
          <div @click="checkeqinfo(scope.row)" style="color:#26a2ff;cursor:pointer">
            {{scope.row.hash.ep_ename}}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="hash.scale" label="规则型号" width="150"></el-table-column>
      <el-table-column prop="hash.managenum" label="管理编号" width="150"></el-table-column>
      <el-table-column prop="hash.factory_num" label="出厂编号" width="100"></el-table-column>
      <el-table-column label="测量范围" width="150">
        <template slot-scope="scope">
          <div v-html="scope.row.hash.range">{{scope.row.hash.range}}</div>
        </template>
      </el-table-column>
      <el-table-column label="精准度等级" width="200">
        <template slot-scope="scope">
          <div v-html="scope.row.hash.accuracy">{{scope.row.hash.accuracy}}</div>
        </template>
      </el-table-column>
      <el-table-column prop="hash.factory" label="生产厂家" width="250"></el-table-column>
      <el-table-column prop="hash.bytime" label="购置日期" width="100"></el-table-column>
      <el-table-column prop="hash.status" label="设备状态">
        <template slot-scope="scope">
          <div
            style="background:#333;color:#fff;text-align:center"
            v-if="scope.row.hash.status=='040301'"
          >正常</div>
          <div
            style="background:#cb0000;color:#fff;text-align:center"
            v-if="scope.row.hash.status=='040302'"
          >过期</div>
          <div
            style="background:#0e90d2;color:#fff;text-align:center"
            v-else-if="scope.row.hash.status=='040303'"
          >到期</div>
          <div
            style="background:#5bb75b;color:#fff;text-align:center"
            v-else-if="scope.row.hash.status=='040304'"
          >送检</div>
          <div
            style="background:#ec971f;color:#fff;text-align:center"
            v-else-if="scope.row.hash.status=='040305'"
          >停用</div>
        </template>
      </el-table-column>
      <el-table-column prop="hash.traceability" label="溯源方式"></el-table-column>
      <el-table-column prop="hash.verifiy_company" label="检定/校准单位" width="250"></el-table-column>


      <el-table-column prop="hash.verifiytime" label="本次检定/校准日期" width="100"></el-table-column>
      <el-table-column prop="hash.verifiy_round" label="检定/校准周期"></el-table-column>
      <el-table-column prop="hash.nextverifiytime" label="下次检定/校准日期" width="100"></el-table-column>
      <el-table-column prop="hash.location" label="放置地点"></el-table-column>
      <el-table-column prop="hash.charger" label="负责人"></el-table-column>
      <!-- <el-table-column label="设备图片" width="150">
        <template slot-scope="scope">
          <el-image
            v-if="scope.row.hash.equ_photo!==''"
            style="width: 100px; height: 100px;cursor:pointer"
            :src="scope.row.hash.equ_photo"
            fit="fill"
            @click="checkeqphoto(scope.row.hash.equ_photo)"
          ></el-image>
        </template>
      </el-table-column> -->
      <el-table-column prop="hash.orgname" label="所属部门" width="210"></el-table-column>
      <el-table-column prop="hash.remark" label="备注"></el-table-column>

      <el-table-column label="操作" width="100" v-if="ismanager">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="primary" @click="addsoneq(scope.row)">添加子设备</el-button> -->
          <el-button
            size="mini"
            type="primary"
            style="margin:5px auto"
            @click="checkeqrecord(scope.row)"
          >检定记录</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="handleCurrentChange"
      :currentPage.sync="pagobj.currentPage3"
      :pageSize="pagobj.pagesize"
      layout="total, prev, pager, next"
      :total="pagobj.total"
      style="margin:20px 0;text-align:center"
    ></el-pagination>
    <!-- <addeq3 v-if="addeq3" :maineq="maineq" :eqtype="eqtype"></addeq3> -->

    <el-dialog title="检定记录" :visible.sync="dialogVisible" width="80%">
      <scheduletable v-if="isscheduletable" :schedulelist="schedulelist" :usertype="1"></scheduletable>
    </el-dialog>
    <!-- <el-dialog :visible.sync="photo">
      <img width="100%" :src="photourl" alt/>
    </el-dialog> -->
    <checkeq v-if="ischeckeq" :isedit="true" :editdata="editdata"></checkeq>
  </div>
</template>

<script>
// import addeq3 from '~/components/apparatus/eqmanager/addeq3.vue';
import scheduletable from '~/components/apparatus/eqschedule/scheduletable2.vue';
import checkeq from '~/components/apparatus/eqmanager/checkeq.vue';

export default {
  components: {
    // addeq3,
    scheduletable,
    checkeq,
  },

  data() {
    return {
      ischeckeq: false,
      editdata: {},
      photo: false,
      photourl: '',
      dialogVisible: false,
      isscheduletable: false,
      ts: this.newStore(),
      // addeq3: false,
      // maineq: {},
      schedulelist: [],
      pagobj2: {
        currentPage3: 1,
        pagesize: 100000,
        total: '',
      },
    };
  },
  props: {
    ismanager: Boolean,
    eqlist: {
      type: Array,
      required: true,
    },
    pagobj: {
      type: Object,
      required: true,
    },
    choosedp: Array,
    eqtype: String,
  },
  methods: {
    checkeqinfo(item) {
      const req = {
        handle: 'DD5D108B99FC12B72DC0B97F927BBE3DD7F2412F8A4ED57CBFF0B9210751F692',
        id: item.hash.id,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.editdata = ts.d.data;
        this.ischeckeq = false;
        this.$nextTick(() => {
          this.ischeckeq = true;
        });
      });
    },
    checkeqphoto(imgurl) {
      console.log(imgurl);
      if (imgurl != '') {
        this.photourl = imgurl;
        this.photo = true;
      }
    },
    checkeqrecord(item) {
      console.log(item);
      const req = {
        handle:
          'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7A4BDCEC5DB08E43DBCD3A43E9777C4E90',
        eid: item.hash.id,
        start: '0',
        limit: '100000',
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.schedulelist = ts.d.data.operation1;
        this.reload2();
        this.dialogVisible = true;
      });
    },
    // reload() {
    //   this.addeq3 = false;
    //   this.$nextTick(() => {
    //     this.addeq3 = true;
    //   });
    // },
    reload2() {
      this.isscheduletable = false;
      this.$nextTick(() => {
        this.isscheduletable = true;
      });
    },
    geteqlist() {
      this.$parent.geteqlist();
    },
    // addsoneq(item) {
    //   console.log(item);
    //   this.maineq = item;
    //   this.reload();
    // },
    handleCurrentChange() {
      this.$parent.geteqlist();
    },
    handleSelectionChange(val) {
      this.$emit('update:choosedp', val);
    },
  },
};
</script>

<style>
</style>
